package logic

import (
	"cart_srv/models/redis"
	"context"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartSumLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartSumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartSumLogic {
	return &CartSumLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartSumLogic) CartSum(in *cart.CartSumRequest) (*cart.CartSumResponse, error) {
	// todo: add your logic here and delete this line

	sum, f, err := redis.CartSum(int(in.UserId))
	if err != nil {
		return nil, err
	}

	return &cart.CartSumResponse{Count: int32(sum), Amount: float32(f)}, nil
}
